package com.aaa.hospital.Client.controller;

import com.aaa.hospital.Client.pojo.Visitingcard;
import com.aaa.hospital.Client.service.VisitingcardService;
import com.aaa.hospital.ManagementEnd.pojo.ExpenseCalendar;
import com.aaa.hospital.ManagementEnd.service.ExpenCalendService;
import com.aaa.hospital.ManagementEnd.service.MedChargeSerevice;
import com.aaa.hospital.ManagementEnd.service.UserServices;
import com.sun.org.apache.bcel.internal.generic.IFNE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.PathParam;

@Controller
public class VisitingcardController {
    @Autowired
    private VisitingcardService visitingcardService;
    @Autowired
    private UserServices userServices;
    @Autowired
    private ExpenCalendService expenCalendService;
    @Autowired
    private MedChargeSerevice medChargeSerevice;
    @RequestMapping("/insertBalance")
    @ResponseBody
    public int insertBalance(@PathParam("balance") Integer balance,@PathParam("uname") String uname,@PathParam("idcard") String idcard){
        Integer res = userServices.queryUid(uname,idcard);
        int result = visitingcardService.insertBalance(balance, res);
        if(result>0){
            Visitingcard i = userServices.queryByIdCard(uname, idcard);
            boolean  ecInsert= expenCalendService.etInsert(new ExpenseCalendar(null, i.getVisid(), null, "办卡充值", balance));
            if(ecInsert==true){
                return i.getVisid();
            }
        }
        return 0;
    }
    @RequestMapping("/updateBalance")
    @ResponseBody
    public Integer updateBalance(@PathParam("visid") Integer visid,@PathParam("balance") Integer balance){
        int result = visitingcardService.updateBalance(visid, balance);
        if(result>0){
            boolean res=expenCalendService.etInsert(new ExpenseCalendar(null, visid, null, "充值", balance));
            if (res == true) {
                return 1;
            }
        }
        return 0;
    }
    @RequestMapping("/refundBalance")
    @ResponseBody
    public Boolean refundBalance(Integer visid,Integer price){
        boolean visprice = medChargeSerevice.visprice(visid, price);
        if(visprice==true){
            return expenCalendService.ecInsert(new ExpenseCalendar(null,visid,null,"就诊卡退款",price));
        }
        return false;
    }
}
